﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;

namespace EAGL.Display.Rendering
{
    public class ValueAreaRenderer: Renderer
    {
     #region =================== PROTECTED ===================

        protected Color defaultFillColor;
        protected esriSimpleFillStyle defaultFillStyle;
        protected Color defaultOutlineColor;
        protected double defaultOutlineWidth;
        protected bool useDefaultVariables;
        protected ValueRenderingMap renderingMap;
        private string[] fields;

        

        protected override void createRenderer()
        {
            ISimpleFillSymbol fsym = new SimpleFillSymbolClass();
            fsym.Color = ColorManager.GetESRIColor(this.defaultFillColor);
            fsym.Style = this.defaultFillStyle;
            ILineSymbol lsym = new SimpleLineSymbolClass();
            lsym.Color = ColorManager.GetESRIColor(this.defaultOutlineColor);
            lsym.Width = this.defaultOutlineWidth;
            fsym.Outline = lsym;

            IUniqueValueRenderer r = new UniqueValueRendererClass();
            r.DefaultSymbol = fsym as ISymbol;
            r.UseDefaultSymbol = this.useDefaultVariables;
            r.FieldCount = this.fields.Length;

            int xx = 0;
            foreach (string s in fields)
            {
                r.set_Field(xx, s);
                xx++;
            }

            
            foreach(ValueRenderingMapRow row in renderingMap.List)
            {
                r.AddValue(row.value.ToString(), "", row.symbol);
                
            }
            
           
            this.renderer = r as IFeatureRenderer;
        }
        
     #endregion


     #region =================== PUBLIC ======================
        
        public ValueAreaRenderer(string Label, string Description, ValueRenderingMap RenderingMap)
        {
            this.label = Label;
            this.description = Description;
            this.renderingMap = renderingMap;
            
            // assign default values
            this.defaultFillColor = Color.Beige;
            this.defaultFillStyle = esriSimpleFillStyle.esriSFSSolid;
            this.defaultOutlineColor = Color.Black;
            this.defaultOutlineWidth = 1;
            this.useDefaultVariables = true;
        }

        public ValueAreaRenderer(string Label)
            : this(Label, "", null) { }

        public ValueAreaRenderer()
            : this("") { }

        public ValueAreaRenderer(ValueRenderingMap RenderingMap)
            : this("", "", RenderingMap) { }


        public Color DefaultFillColor
        {
            get { return this.defaultFillColor; }
            set { this.defaultFillColor = value; }
        }

        public esriSimpleFillStyle DefaultFillStyle
        {
            get { return this.defaultFillStyle; }
            set { this.defaultFillStyle = value; }
        }

        public Color DefaultOutlineColor
        {
            get { return this.defaultOutlineColor; }
            set { this.defaultOutlineColor = value; }
        }

        public double DefaultOutlineWidth
        {
            get { return this.defaultOutlineWidth; }
            set { this.defaultOutlineWidth = value; }
        }

        public bool UseDefaultVariables
        {
            get { return this.useDefaultVariables; }
            set { this.useDefaultVariables = value; }
        }

        public ValueRenderingMap RenderingMap
        {
            get { return this.renderingMap; }
            set { this.renderingMap = value; }
        }

        public string[] Fields
        {
            get { return fields; }
            set { fields = value; }
        }
        
     #endregion

    }
}
